﻿#$language = "Python"
#$interface = "1.0"

import os
import sys

g_local_path = os.path.dirname(os.path.abspath(__file__))
g_common_path = g_local_path + "\\common"
if g_common_path not in sys.path:
    sys.path.insert(0, g_common_path)

import crnc
import debug
import screen
import plan_crnc
from const import *

def main():
    crt.Screen.Synchronous = True
    debug.log_start(__file__)
    log = debug.Log('')
    msg = 'Plan Operate.\n' + \
          'Yes ==> Active a new Plan to RNC.\n' + \
          'No ==> Upload RNC Plan'
    act_choice = crt.Dialog.MessageBox(msg, 'Choice Operation', 32 | 3)
    if act_choice == 2:  # IDCANCEL
        log.w('Operate canceled.')
        rslt = False
    else:
        session_name = (crt.Session.Path).split('\\').pop()
        if act_choice == 6: # IDYES
            msg = 'Download and Active plan in ' + session_name
        else:
            msg = 'Upload plan in ' + session_name
        log.w(msg, head='Operate: ', end=' ')
    
        prompt = screen.Prompt()
        prompt.set_prompt(crt)
    
        if prompt.style == CONST_STYLE_CRNC:
            plan = plan_crnc.cRnwPlan(crt, True)
            log.w(plan.rnc.ip)
            if act_choice == 6:  # IDYES
                rslt = plan.download_plan() and plan.active_plan()
            else:
                rslt = plan.upload_plan()
            del plan
        else:
            log.w('\nThis session {0} not support yet.'.format(prompt.style))
            rslt = False
        del prompt
    del log
    crt.Screen.Synchronous = False
    return rslt

main()
